package listbyorder.access001_100.test77;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/4 10:36
 */
public class Solution1 {

    public List<List<Integer>> combine(int n, int k) {
        List<List<Integer>> res = new ArrayList<>();
        if (n == 0 || n < k || k == 0) return res;
        dfs(res, new ArrayDeque<Integer>(), 1, n, k);
        return res;
    }

    private void dfs(List<List<Integer>> res, ArrayDeque<Integer> path, int s, int n, int k) {
        if (path.size() == k) {
            res.add(new ArrayList<>(path));
            return;
        }
        for (int i = s; i <= n; i++) {
            path.addLast(i);
            dfs(res, path, i + 1, n, k);
            path.removeLast();
        }
    }
}
